package com.yanqu.road.logic.pb;

import com.google.protobuf.AbstractMessage;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangActivityEventConfig;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangFloorConfig;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangStrongPoint;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangTreasure;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;

import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * @Author wpj
 * @Date 2020/10/7
 */
public class HuaShiGangPb {

    public static HuaShiGangProto.GetTreasureListMsgRespMsg.Builder getHuaShiGangTreasureListPb(List<HuaShiGangTreasure> treasureList) {
        HuaShiGangProto.GetTreasureListMsgRespMsg.Builder builder = HuaShiGangProto.GetTreasureListMsgRespMsg.newBuilder();
        builder.setRet(0);
        for (HuaShiGangTreasure treasure : treasureList) {
            builder.addTreasure(getHuaShiGangTreasurePb(treasure));
        }
        return builder;
    }

    public static HuaShiGangProto.HuaShiGangTreasureEntity.Builder getHuaShiGangTreasurePb(HuaShiGangTreasure treasure) {
        HuaShiGangProto.HuaShiGangTreasureEntity.Builder builder = HuaShiGangProto.HuaShiGangTreasureEntity.newBuilder();
        builder.setTreasureId(treasure.getTreasureId());
        builder.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(treasure.getOpenPlayer()));
        builder.setIsGoodReward(false);
        builder.setOpenTime(treasure.getOpenTime());
        if (treasure.getOpenTime() > 0) {
            // 已经被打开
            builder.setReward(treasure.getReward());
        } else {
            builder.setReward("");
        }
        return builder;
    }

    /**
     * 获取花石纲活动
     *
     * @param activityId
     * @param eventConfigBuilderList
     * @param integerHuaShiGangFloorConfigMap
     * @return
     */
    public static AbstractMessage.Builder<?> getHuaShiGangActivity(int activityId, List<HuaShiGangProto.EventConfigEntity> eventConfigBuilderList, Map<Integer, HuaShiGangFloorConfig> integerHuaShiGangFloorConfigMap) {
        HuaShiGangProto.HuaShiGangActivity.Builder builder = HuaShiGangProto.HuaShiGangActivity.newBuilder();
        builder.setActivityId(activityId);

        builder.addAllEvent(eventConfigBuilderList);


        for (HuaShiGangFloorConfig config : integerHuaShiGangFloorConfigMap.values()) {
            builder.addFloor(getFloorPb(config));
        }

        return builder;

    }

    private static HuaShiGangProto.FloorConfigEntity.Builder getFloorPb(HuaShiGangFloorConfig config) {
        HuaShiGangProto.FloorConfigEntity.Builder builder = HuaShiGangProto.FloorConfigEntity.newBuilder();
        builder.setFloor(config.getFloor());
        builder.setConsume(config.getConsume());
        builder.setRewards(config.getRewards());
        builder.setSpecialReward(config.getSpecialReward());
        return builder;
    }


    public static Iterable<? extends HuaShiGangProto.HuaShiGangPointEntity> getHuaShiGangStrongPointPbList(List<HuaShiGangStrongPoint> pointList) {
        List<HuaShiGangProto.HuaShiGangPointEntity> entityList = new ArrayList<>();
        for (HuaShiGangStrongPoint strongPoint : pointList) {
            entityList.add(getHuaShiGangPointEntityPb(strongPoint).build());
        }
        return entityList;
    }

    public static HuaShiGangProto.HuaShiGangPointEntity.Builder getHuaShiGangPointEntityPb(HuaShiGangStrongPoint point) {
        HuaShiGangProto.HuaShiGangPointEntity.Builder builder = HuaShiGangProto.HuaShiGangPointEntity.newBuilder();
        builder.setP(getPointPb(new Point(point.getX(), point.getY())));
        builder.setEventId(point.getEventId());
        for (Point p : point.getNextList()) {
            builder.addNext(getPointPb(p));
        }
        return builder;
    }

    public static HuaShiGangProto.Point.Builder getPointPb(Point point) {
        HuaShiGangProto.Point.Builder pointBuilder = HuaShiGangProto.Point.newBuilder();
        pointBuilder.setX(point.x);
        pointBuilder.setY(point.y);
        return pointBuilder;
    }

    public static HuaShiGangProto.HuaShiGangEventLog.Builder getHuaShiGangEventLogPb(int activityId, int eventType, int eventId) {
        HuaShiGangProto.HuaShiGangEventLog.Builder builder = HuaShiGangProto.HuaShiGangEventLog.newBuilder();
        builder.setActivityId(activityId);
        builder.setEventType(eventType);
        builder.setEventId(eventId);
        return builder;
    }

    public static HuaShiGangProto.HuaShiGangNotifyChoosePatronsLog.Builder getHuaShiGangPatronsLogPb(int activityId, int patronsId, int oldAddition, int distanceAddition, int newAddition) {
        HuaShiGangProto.HuaShiGangNotifyChoosePatronsLog.Builder builder = HuaShiGangProto.HuaShiGangNotifyChoosePatronsLog.newBuilder();
        builder.setActivityId(activityId);
        builder.setPatronsId(patronsId);
        builder.setOldAddition(oldAddition);
        builder.setDistanceAddition(distanceAddition);
        builder.setNewAddition(newAddition);
        return builder;
    }

    public static HuaShiGangProto.HuaShiGangMallEntity.Builder parseHuaShiGangMallEntity(int mallId, long mallTime, int mallTimes){
        HuaShiGangProto.HuaShiGangMallEntity.Builder msg = HuaShiGangProto.HuaShiGangMallEntity.newBuilder();
        msg.setMallId(mallId);
        msg.setTime(mallTime);
        msg.setCanBuyTimes(mallTimes);
        return msg;
    }
}
